<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<s:head theme="ajax" debug="true"/>
		<script type="text/javascript">
			dojo.event.topic.subscribe("/save", function(data, type, request) {
			    if(type == "load") {
					dojo.byId("id").value = "";
					dojo.byId("description").value = "";
					dojo.byId("lang").value = "";
				}
			});

			dojo.event.topic.subscribe("/edit", function(data, type, request) {
			    if(type == "before") {
					var id = data.split("_")[1];
					var tr = dojo.byId("row_"+id);
					var tds = tr.getElementsByTagName("td");
					dojo.byId("id").value = id;
					dojo.byId("description").value = dojo.string.trim(dojo.dom.textContent(tds[0]));
					dojo.byId("lang").value = dojo.string.trim(dojo.dom.textContent(tds[1]));
				}
			});
		</script>
	</head>

	<body>

	    <s:url action="listFile" id="descrsUrl"/>

        <div style="width: 300px;border-style: solid">
        	<div style="text-align: right;">
    			<s:a theme="ajax" notifyTopics="/refresh">Refresh</s:a>
    		</div>
    		<s:div id="files" theme="ajax" href="%{descrsUrl}" loadingText="Loading..." listenTopics="/refresh"/>
        </div>

        <br/>

		<div style="width: 300px;border-style: solid">
			<p>Datos del fichero</p>
			<s:form action="saveFile" method="POST" enctype="multipart/form-data">
				<s:textfield id="id" name="id" cssStyle="display:none"/>
				<s:file name="upload" id="upload" label="Fichero"/>
				<s:textfield name="description" id="description" label="Descripcion"/>
				<s:select label="Idioma" id="lang" name="lang"
       				list="#{'es':'Castellano', 'eu':'Euskera'}"
			       	value="lang"
       				required="true"/>
				<s:submit theme="ajax" targets="files" notifyTopics="/save"/>
			</s:form>
		</div>

	</body>

</html>